package org.vy.dal.dao;

import java.util.List;

import org.vy.dal.QueryManager;

public class ViewVyPrintLabelDAO {

	private static final String FIND_BY_PARAM = "SELECT * FROM <TABLE> WHERE <PARAM> ";
	private static final String FIND_BY_PRINT_LABEL_GROUP_ID = "SELECT * FROM <TABLE> WHERE PRINT_LABEL_GROUP_ID = m_PrintLabelGroupId";
	private static final String FIND_BY_VYID = "SELECT * FROM <TABLE> WHERE VY_ID = m_VyId";
	private static final String FIND_BY_VYID_IN = "SELECT * FROM <TABLE> WHERE VY_ID IN (<PARAM>)";
	private static final String FIND_BY_SUBSCRIPTION_ID = "SELECT * FROM <TABLE> WHERE SUBSCRIPTION_ID IN (<PARAM>)";
	private static final String FIND_BY_GROUP_VY_ID = "SELECT * FROM <TABLE> WHERE VY_ID = m_VyId AND PRINT_LABEL_GROUP_ID = m_PrintLabelGroupId";

	public static ViewVyPrintLabelDO findByPK(String groupId, String vyId) throws Exception {
		ViewVyPrintLabelDO dto = new ViewVyPrintLabelDO();
		dto.setPrintLabelGroupId(groupId);
		dto.setVyId(vyId);
		dto = (ViewVyPrintLabelDO) QueryManager.executeQuery(dto,
				FIND_BY_GROUP_VY_ID);
		return dto;
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyPrintLabelDO> findByVyId(String vyId)
			throws Exception {
		ViewVyPrintLabelDO dto = new ViewVyPrintLabelDO();
		dto.setVyId(vyId);
		return (List<ViewVyPrintLabelDO>) QueryManager.executeListQuery(dto,
				FIND_BY_VYID);
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyPrintLabelDO> findByParam(String params)
			throws Exception {
		ViewVyPrintLabelDO dto = new ViewVyPrintLabelDO();
		String sql = FIND_BY_PARAM.replaceAll("<PARAM>", params);
		return (List<ViewVyPrintLabelDO>) QueryManager.executeListQuery(dto, sql);
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyPrintLabelDO> findBySubscriptionIds(String[] subIds)
			throws Exception {
		StringBuilder ids = new StringBuilder();
		ViewVyPrintLabelDO dto = new ViewVyPrintLabelDO();
		for(String id : subIds){
			ids.append("'").append(id).append("',");
		}
		String sql = FIND_BY_SUBSCRIPTION_ID.replaceAll("<PARAM>", ids.substring(0, ids.length()-1));
		return (List<ViewVyPrintLabelDO>) QueryManager.executeListQuery(dto, sql);
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyPrintLabelDO> findByVyIdList(String[] vyIds)
			throws Exception {
		StringBuilder ids = new StringBuilder(); 
		ViewVyPrintLabelDO dto = new ViewVyPrintLabelDO();
		for(String id : vyIds){
			ids.append("'").append(id).append("',");
		}
		String sql = FIND_BY_VYID_IN.replaceAll("<PARAM>", ids.substring(0, ids.length()-1));
		return (List<ViewVyPrintLabelDO>) QueryManager.executeListQuery(dto, sql);
	}

	@SuppressWarnings("unchecked")
	public static List<ViewVyPrintLabelDO> findByGroupId(String groupId)
			throws Exception {
		ViewVyPrintLabelDO dto = new ViewVyPrintLabelDO();
		dto.setPrintLabelGroupId(groupId);
		return (List<ViewVyPrintLabelDO>) QueryManager.executeListQuery(dto,
				FIND_BY_PRINT_LABEL_GROUP_ID);
	}
}
